<template>
    <div id="Login">
        <div id="loginBox">
            <el-form :model="loginForm" status-icon :rules="loginRules" ref="ruleForm"  label-width="80px" class="demo-ruleForm" id="loginForm">
                <el-form-item label="账号:" prop="username">
                    <el-input type="text" v-model="loginForm.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码:" prop="password">
                    <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="login()">提交</el-button>
                    <el-button >重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data() {
            return {
                loginForm: {username: "123456", password: "123456"},
                //登录的规则
                loginRules: {
                    username: [
                        {required: true, message: '请输入账号', trigger: 'blur'},
                    ],
                    password: [
                        {required: true, message: '请输入密码', trigger: 'blur'},
                    ]
                }
            }
        },
        methods:{
            login(){
                this.$book.post("http://localhost:7002/login",this.loginForm).then(resp=>{
                    if(resp.data.code===200){
                        localStorage.setItem("token",resp.data.data);
                        this.$router.push("/Test")
                    }else {
                        this.$message.error("账号或密码错误")
                    }
                })
            }
        }


    }
</script>

<style scoped>
    #loginBox{
        width: 450px;
        height: 300px;
        margin: 150px auto;

    }
    #loginForm{
        margin: 20px auto;
    }
</style>